package com.example.tool.action;

import com.example.tool.ui.HToolIcon;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * <p>Title: ShowTipsActions</p >
 * Description: 打开目标路径
 * <p>CreateTime: 2022/6/28 11:20</p>
 * @author FT
 */
public class ShowFileActions extends AnAction {

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    try {
      String[] information = ActionUtil.getInformation(e.getProject());
      if (information != null) {
        String base = information[0];
        String property = System.getProperty("os.name");
        if (property.contains("Windows")) {
          Runtime.getRuntime().exec("explorer.exe /e /select," + base);
        } else {
          Runtime.getRuntime().exec("open " + base);
        }
      } else {
        Messages.showMessageDialog(
            e.getProject(),
            "Profile was not found. Failed to open file resource path!",
            "Error",
            HToolIcon.ModuleIcon);
      }
    } catch (IOException ex) {
      Messages.showMessageDialog(
          e.getProject(),
          "Failed to open file resource path!",
          "Error",
          HToolIcon.ModuleIcon);
      ex.printStackTrace();
    }
  }
}
